package com.heima.article.listen;

import com.heima.article.service.ApArticleService;
import com.heima.common.message.PublishArticleConstants;
import lombok.extern.slf4j.Slf4j;
import org.springframework.amqp.rabbit.annotation.Queue;
import org.springframework.amqp.rabbit.annotation.RabbitListener;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Component;

import java.time.LocalDateTime;

/**
 * @author mrchen
 * @date 2022/8/1 14:39
 */
@Component
@Slf4j
public class PublishArticleListener {
    @Autowired
    ApArticleService apArticleService;
    @RabbitListener(queuesToDeclare = @Queue(PublishArticleConstants.PUBLISH_ARTICLE_QUEUE))
    public void handlePublishArticleMsg(String newsId){
        log.info("成功接收到  定时发布文章消息  消息内容:{}  触发时间:{}",newsId, LocalDateTime.now().toString());
        apArticleService.publishArticle(Integer.valueOf(newsId));
    }
}